<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		function objectCopy(obj) {
			function Fun() { };
			Fun.prototype = obj;
			return new Fun()
		}

		let person = {
			name: "yhd",
			age: 18,
			friends: ["jack", "tom", "rose"],
			sayName: function () {
				console.log(this.name);
			}
		}

		let person1 = objectCopy(person);
		person1.name = "wxb";
		person1.friends.push("lily");
		person1.sayName(); // wxb

		let person2 = objectCopy(person);
		person2.name = "gsr";
		person2.friends.push("kobe");
		person2.sayName(); // "gsr"

		console.log(person.friends); // ["jack", "tom", "rose", "lily", "kobe"]
	</script>
</body>

</html>